package cn.school.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author oldliu
 * @since 1.0
 */
public class StringUtil {
    private StringUtil() {
    }
    public static String trimNull(String s) {
        return s==null?"":s.trim();
    }
    public static int toInt(String s) {
        return Integer.valueOf(s);
    }
    public static long toLong(String s) {
        return Long.valueOf(s);
    }
    public static int toInt(String s, int def) {
        try {
            return Integer.valueOf(s);
        } catch (Exception e) {

        }
        return def;
    }

    public static int toIntGt0(String s, int def) {
        int i = toInt(s, def);
        return i <= 0 ? 1 : i;
    }
    public static final SimpleDateFormat DF=new SimpleDateFormat("yyyy-MM-dd");
    public static Date toDate(String s) {
        try {
            return DF.parse(s);
        } catch (Exception e) {
            //e.printStackTrace();
        }
        return null;
    }
}
